<template>
  <ArmyPanelLayout class="barracksLeftTwo" title="库房状态">
    <div class="barracksLeftTwo--table" v-if="tableData.length">
      <div class="barracksLeftTwo--table__header row">
        <div class="th one">仓库名称</div>
        <div class="th two">操作时间</div>
        <div class="th four">当前状态</div>
      </div>
      <div class="barracksLeftTwo--table__body">
        <!--<el-scrollbar height="236px">-->
        <el-scrollbar wrap-style="overflow:hidden" view-style="height: 365px;overflow: hidden;" :always="false">
          <div class="tablelist">
            <div class="row" :class="{'two': (index % 2 !== 0)}" v-for="(item, index) in tableData" :key="index">
              <div class="row--item one" :title="item.houseName">{{ item.houseName || '--' }}</div>
              <div class="row--item two" :title="item.time">{{ item.time || '--' }}</div>
              <div class="row--item four" :title="item.defenseStatus">
                <span :style="getTypeStyle(item.defenseStatus)">{{ item.defenseStatus || '--' }}</span>
              </div>
            </div>
          </div>
        </el-scrollbar>
      </div>
    </div>
    <div v-else class="empty">
      <DataEmptyTwo></DataEmptyTwo>
    </div>
  </ArmyPanelLayout>
</template>

<script>
import ArmyPanelLayout from '@/views/armyScreen/comp/ArmyPanelLayout.vue'
import {houseInfoService} from '@/api/armyScreenApiV2.js'
import {random14} from '@/util/utils.js'
import {ElScrollbar} from 'element-plus'
import DataEmptyTwo from "@/components/common/DataEmptyTwo.vue";
import useCommonMethods from "@/mixin/useCommonMethods";
import $bus from "@/util/bus";
export default {
  inject: ['warnInfo'],
  components: {
    DataEmptyTwo,
    ElScrollbar,
    ArmyPanelLayout,
  },
  data() {
    return {
      sid: 'chart_' + random14(),
      tabList: [],
      tabActive: '',
      tableData: []
    }
  },
  watch: {
    warnInfo : function () {
      if (this.warnInfo) {
        console.log('watch(warnInfo  监听，重新查询仓库信息', this.warnInfo)
        this.getHouseInfoService()
      }
    }
  },
  setup() {
    const {dictByTypeService} = useCommonMethods()
    return {
      dictByTypeService
    }
  },
  async mounted() {
    this.getHouseInfoService()
    $bus.on('reRequest', this.getHouseInfoService)
  },
  beforeUnmount() {
    $bus.off('reRequest', this.getHouseInfoService)
  },
  methods: {
    getTypeStyle(actionName) {
      // 还是原来的 ，已撤防 -蓝色，已布防-红色
      if (actionName === '已撤防') {
        return 'color: #32C5FF;'
      } else {
        return 'color: #EE4A45;'
      }
    },
    /**
     * 将后台返回的日期 格式化
     * @param dateStr {string} 日期字符串
     */
    transformDate(dateStr) {
      if (dateStr) {
        return dateStr.substring(0, 10) + ' ' + dateStr.substring(11, 20)
      } else {
        return null
      }
    },
    tabChangeAction(value) {
      this.tabActive = value
      this.getHouseInfoService()
    },
    getHouseInfoService() {
      houseInfoService().then(res => {
        this.tableData = res?.data || []
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.barracksLeftTwo {
  width: 439px;
  height: 460px;
  background-image: none;
  backdrop-filter: blur(10px);

  &--table {
    width: 420px;
    margin: 0 auto;
    margin-top: 16px;

    .row {
      height: 28px;
      line-height: 28px;
      display: flex;

      div {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis
      }

      .one {
        padding-left: 12px;
        flex: 1;
      }

      .two {
        flex: 1;
      }

      .three {
        width: 50px;
      }

      .four {
        width: 80px;
      }
    }

    &__header {
      display: flex;
      height: 28px;
      line-height: 28px;
      background: rgba(21, 77, 160, 0.20);
      font-family: PingFangSC-Regular;
      font-size: 12px;
      color: #D8F0FF;
      letter-spacing: 0;
      font-weight: 400;
    }

    &__body {
      .tablelist {
        width: 100%;
        animation: move 6s linear infinite normal;
        overflow-x: hidden;

        &:hover {
          animation-play-state: paused;
        }
      }

      .row {
        &.two {
          background-image: url('@/assets/images/armyScreen/通行记录_底纹@2x.png');
          background-size: cover;
        }

        font-family: PingFangSC-Regular;
        font-size: 14px;
        color: rgba(216, 240, 255, 0.80);
        letter-spacing: 0;
        font-weight: 400;
      }
    }
  }

  .empty {
    width: 100%;
    height: 200px;
  }

  @keyframes move {
    0% {
      transform: translateY(0);
    }
    100% {
      transform: translateY(calc(-100% + 365px));
    }
  }
}
</style>
